import { _decorator, AnimationClip, Animation, Component, Node } from "cc"
import { FSM_PARAMS_TYPE_ENUM, PARAME_NAME_ENUM } from "../Enums"
import State from "./state"

const { ccclass, property } = _decorator
export const getParamsTrigger = () => {
  return {
    type: FSM_PARAMS_TYPE_ENUM.TRIGGER,
    value: false
  }
}
export const getParamsNumber = () => {
  return {
    type: FSM_PARAMS_TYPE_ENUM.NUMBER,
    value: false
  }
}
@ccclass("StateMachine")
export abstract class StateMachine extends Component {
  private _currentState = null
  params = new Map()
  stateMachines = new Map()
  animationComp
  waitingList = []

  getParams(paramsName) {
    if (this.params.has(paramsName)) return this.params.get(paramsName).value
  }
  setParams(paramsName, value) {
    if (this.params.has(paramsName)) {
      this.params.get(paramsName).value = value
      this.run(paramsName, value)
      this.resetTrigger()
    }
  }
  resetTrigger() {
    for (const [_, v] of this.params) {
      if (v.type === FSM_PARAMS_TYPE_ENUM.TRIGGER) {
        v.value = false
      }
    }
  }
  get currentState() {
    return this._currentState
  }
  set currentState(newState) {
    this._currentState = newState
    this._currentState.run()
  }
  abstract init(): void
  abstract run(paramsName, value): void

  update(deltaTime: number) {}
}
